<template>
  <el-dialog :title="option.title" :visible.sync="isShow" width="890px" @open="openCreate" @close="closedialog"
    :close-on-click-modal="false" center>
    <div v-loading="loading">
      <div class="content">
        <el-card>
          <el-form size="mini" ref="form" :model="form" label-width="150px" label-position="left" :rules="rules">
            <el-row :gutter="10">
              <el-col :span="12">
                <el-form-item label="机构名称" prop="AGENTDEP">
                  <el-input v-model.trim="form.BRANCHNAME" size="small" :disabled="option.isDetail"
                    v-if="option.isDetail"></el-input>
                  <select-tree :branch="form.BRANCHNAME" @getBranchName="getBranch" v-if="!option.isDetail">
                  </select-tree>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="AGENTID" label="坐席ID">
                  <el-input v-model="form.AGENTID" placeholder="请输入坐席ID" :disabled="option.isChecked||option.isDetail">
                  </el-input>
                </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="10">
              <el-col :span="12">
                <el-form-item prop="AGENTNAME" label="坐席名">
                  <el-input v-model="form.AGENTNAME" placeholder="请输入坐席名" :disabled="option.isDetail"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="AGENTSEX" label="性别">
                  <el-select v-model="form.AGENTSEX" filterable placeholder="请选择性别" :disabled="option.isDetail">
                    <el-option v-for="item in AGENTSEXLIST" :key="item.value" :label="item.name" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="AGENTROLE" label="坐席角色">
                  <el-select v-model="form.AGENTROLE" filterable placeholder="请选择坐席角色" :disabled="option.isDetail">
                    <el-option v-for="item in AGENTROLELIST" :key="item.value" :label="item.name" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="STAFSTS" label="人员状态">
                  <el-select v-model="form.STAFSTS" filterable placeholder="请选择人员状态" :disabled="option.isDetail">
                    <el-option v-for="item in STAFSTSLIST" :key="item.value" :label="item.name" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="AGENTCLASS" label="班">
                  <el-select v-model="form.AGENTCLASS" filterable placeholder="请选择班" :disabled="option.isDetail"
                    @change="changeClass">
                    <el-option v-for="item in STeamTypeList" :key="item.TEAMID" :label="(item.TEAMID+'-'+item.TEAMNAME)"
                      :value="item.TEAMID"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="AGENTTEAM" label="组">
                  <el-select v-model="form.AGENTTEAM" filterable placeholder="请选择组"
                    :disabled="form.AGENTDEP=='' || option.isDetail">
                    <el-option v-for="item in teamOption" :key="item.TEAMID" :label="(item.TEAMID+'-'+item.TEAMNAME)"
                      :value="item.TEAMID"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="TELPHONE" label="	联系方式">
                  <el-input v-model="form.TELPHONE" placeholder="请输入联系方式" :disabled="option.isDetail"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="EMAIL" label="邮箱">
                  <el-input v-model="form.EMAIL" placeholder="请输入邮箱" :disabled="option.isDetail"></el-input>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="AGENTLEVEL" label="坐席等级">
                  <el-select v-model="form.AGENTLEVEL" filterable placeholder="请选择坐席等级" :disabled="option.isDetail">
                    <el-option v-for="item in AGENTLEVELLIST" :key="item.value" :label="item.name" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item prop="LOGINFLG" label="登录方式">
                  <el-select v-model="form.LOGINFLG" filterable placeholder="请选择登录方式" :disabled="option.isDetail">
                    <el-option v-for="item in LOGINFLGLIST" :key="item.value" :label="item.name" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12" :style="{height:'46.88px'}">
                <el-form-item prop="LOGINPWD" label="密码">
                  <el-input v-model.number="form.LOGINPWD" placeholder="请输入密码" :disabled="option.isDetail"
                    :type="form.pass?'text':'password'">
                    <el-switch slot="append" v-model="form.pass" active-color="#13ce66" inactive-color="grey">
                    </el-switch>
                  </el-input>
                </el-form-item>
              </el-col>
              <!-- <el-col :span="12">
                <el-form-item prop="ENGLEVEL" label="英语水平">
                  <el-select v-model="form.ENGLEVEL" filterable placeholder="请选择英语水平" :disabled="option.isDetail">
                    <el-option v-for="item in ENGLEVELLIST" :key="item.value" :label="item.name" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col> -->
              <el-col :span="12">
                <el-form-item prop="SKILLFLG" label="可受理渠道">
                  <el-select v-model="form.SKILLFLG" multiple placeholder="请选择" @change="skillQuery"
                    :disabled="option.isDetail">
                    <el-option v-for="item in SKILLFLGLIST" :key="item.value" :label="item.name" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-button type="primary" size="mini" @click="openBranch"
                  :disabled="form.AGENTDEP=='' || option.log == '1'">配置附属机构</el-button>
                <el-button type="primary" size="mini" @click="openSkill" :disabled="option.log == '1'">配置坐席技能
                </el-button>
              </el-col>
              <!-- <el-col :span="12">
                <el-form-item prop="NUMONLINE" label="同时聊天人数">
                  <el-select v-model="form.NUMONLINE" filterable placeholder="请选择同时聊天人数" :disabled="option.isDetail">
                    <el-option v-for="item in NUMONLINELIST" :key="item.value" :label="item.name" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col> -->
            </el-row>
            <!-- <el-row :gutter="12">
              <el-card class="box-card" v-if="SKILL" :span="24">
                <el-table :data="tableData" ref="tableData" border class="tableMarginTop" highlight-current-row
                  @selection-change="handleCurrentChange" header-row-class-name="tableHeaderClass"
                  style="min-height:390px;">
                  <el-table-column type="selection" width="40px" :disabled="option.isDetail"></el-table-column>
                  <el-table-column show-overflow-tooltip fit="true" prop="SKILLID" label="技能ID"></el-table-column>
                  <el-table-column show-overflow-tooltip fit="true" prop="SKILLNAME" label="技能名称"></el-table-column>
                  <el-table-column show-overflow-tooltip fit="true" prop="APPMODULELEVEL" label="技能等级(1-9级)">

                    <template slot-scope="scope">
                      <el-input type="text" onkeypress="return event.keyCode>=49&&event.keyCode<=57" :maxlength="1"
                        v-model="scope.row.APPMODULELEVEL" placeholder="勾选后输入等级" :disabled="option.isDetail"></el-input>
                    </template>
                  </el-table-column>

                </el-table>


                
              </el-card>
            </el-row> -->
          </el-form>
        </el-card>

        <div style="text-align:center;margin-top:20px">
          <el-button size="mini" @click="isShow=false">取消</el-button>
          <el-button size="mini" type="primary" @click="add" v-if="this.option.showButton">确认</el-button>
        </div>
      </div>
      <!-- 坐席附属机构 -->
      <el-dialog width="50%" title="配置附属机构" :close-on-click-modal="false" :visible.sync="branchIsShow" append-to-body
        @open="openExtraBranch" @close="closeExtraBranch">
        <el-row>
          <el-form size="mini" ref="branchForm" :model="branchForm" label-width="22%" label-position="left">
            <el-col :span="24">
              <el-form-item prop="AGENTDEP" label="附属机构">
                <el-select v-model="branchForm.AGENTDEP" filterable :disabled="option.isDetail" :multiple-limit="3" 
                  placeholder="请选择附属机构" multiple @change="changeBranch">
                  <el-option v-for="item in branchList" :key="item.BRANCHNO" :label="(item.BRANCHNO+'-'+item.BRANCHNAME)"
                    :value="item.BRANCHNO"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item style="margin-top:30px;">
                <el-button type="primary" size="mini" @click="saveExtraBranch" :disabled="option.isDetail">保存
                </el-button>
                <el-button type="danger" size="mini" @click="delExtra" :disabled="option.isDetail">删除</el-button>
              </el-form-item>
            </el-col>
          </el-form>
        </el-row>
      </el-dialog>
      <!-- 坐席技能 -->
      <el-dialog width="70%" title="配置坐席技能" :close-on-click-modal="false" :visible.sync="skillIsShow" append-to-body
        @open="openSkillConfig" @close="closeSkillConfig">
        <el-row>
          <el-col :span="24">
            <el-button :disabled="option.isDetail" type="primary" size="mini" @click="addSkillDialog">新增坐席技能</el-button>
          </el-col>
          <el-col :span="24" style="margin-top:15px;">
            <el-table :data="skillData" style="margin-bottom:30px;">
              <el-table-column prop="SKILLFLG" label="坐席技能">
              </el-table-column>
              <el-table-column prop="SKILLLEVEL" label="坐席熟练度">
              </el-table-column>
              <el-table-column prop="SKILLENABLEDATE" label="生效日期">
              </el-table-column>
              <el-table-column prop="ENABLEHOURS" label="失效日期">
              </el-table-column>
              <el-table-column label="操作">
                <template slot-scope="scope">
                  <div>
                    <el-button type="text" size="mini" :disabled="option.isDetail" @click="openUpdateSkill(scope.row)">
                      修改</el-button>
                    <el-button type="text" size="mini" :disabled="option.isDetail" @click="delSkill(scope.row)">删除
                    </el-button>
                  </div>
                </template>
              </el-table-column>
            </el-table>
          </el-col>
        </el-row>
      </el-dialog>
      <!-- 新增坐席技能 -->
      <el-dialog width="80%" title="新增坐席技能" :visible.sync="addSkillIsShow" @open="openAddSkillDialog"
        @close="closeAddSkillDialog" append-to-body>
        <el-table border ref="multipleTable" :data="skillOption" @selection-change="changeFun" @select="selectMemoryFn"
          @select-all="selectAll">
          <el-table-column type="selection" width="55" :selectable='checkboxInit' align="center"></el-table-column>
          <el-table-column prop="FIELDKEY" label="技能编号" align="center"></el-table-column>
          <el-table-column prop="FIELDVALUE" label="技能名称" align="center"></el-table-column>
          <el-table-column prop="SKILLLEVEL" label="技能熟悉度" align="center">
            <template slot-scope="scope">
              <div>
                <el-input-number size="mini" style="width:100%;" :step="0.1" v-model="scope.row.SKILLLEVEL" :min="0.1"
                  :max="1"></el-input-number>
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="SRTDATE" label="生效日期-失效日期" width='340' align="center">
            <template slot-scope="scope">
              <el-date-picker style="width:100%;" v-model="scope.row.SRTDATE" type="daterange" range-separator="-"
                unlink-panels size="small" value-format="yyyyMMdd" start-placeholder="生效日期" end-placeholder="失效日期">
              </el-date-picker>
            </template>
          </el-table-column>
        </el-table>
        <div style="text-align:right;">
          <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page.sync="currentPage" :page-sizes="[5]" :page-size="pageSize" layout="prev, pager, next"
            :total="tableTotal">
          </el-pagination>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="addSkillIsShow = false;" size="mini">取 消</el-button>
          <el-button type="primary" @click="saveAddSkill" size="mini">新 增</el-button>
        </div>
      </el-dialog>
      <!-- 修改坐席技能 -->
      <el-dialog width="50%" title="修改坐席技能" :close-on-click-modal="false" append-to-body :visible.sync="updateIsShow"
        @close="closeUpdateDialog">
        <el-form ref="updateForm" :rules="updateRules" :model="updateForm" label-width="150px" label-position="left">
          <el-form-item label="坐席技能" prop="SKILLFLG">
            <el-input v-model="updateForm.SKILLFLG" size="mini" disabled></el-input>
          </el-form-item>
          <el-form-item label="技能熟练度" prop="SKILLLEVEL">
            <el-input-number size="mini" :step="0.1" v-model="updateForm.SKILLLEVEL" :min="0.1" :max="1">
            </el-input-number>
          </el-form-item>
          <el-form-item label="有效日期" prop="SRTDATE">
            <el-date-picker style="width:90%;" v-model="updateForm.SRTDATE" type="daterange" range-separator="-"
              unlink-panels size="small" value-format="yyyyMMdd" start-placeholder="生效日期" end-placeholder="失效日期">
            </el-date-picker>
          </el-form-item>
          <el-form-item style="margin-top:30px;">
            <el-button type="primary" size="mini" @click="saveUpdateSkill('updateForm')">修改</el-button>
            <el-button size="mini" @click="updateIsShow=false">取消</el-button>
          </el-form-item>
        </el-form>
      </el-dialog>
    </div>
  </el-dialog>
</template>
<script>
  import agentManage from "@/message/seat-manage/SeatInfoManage/agentManage";
  // 班组接口
  import teamManage from "@/message/seat-manage/setaTeam/teamManage";
  // import skillQuery from "@/message/seat-manage/skillInformationInquire/query";
  import requestYg from "@/common/utils/requestYg";
  import requestWFM from "@/common/utils/requestWFM";
  import getGlobalParams from "@/common/utils/getGlobalParams";
  import queryOne from "@/message/seat-manage/SeatInfoManage/queryOne";
  import extraBranchQuery from '@/message/seat-manage/extraBranch/branchQuery'
  import extraBranchUpdate from '@/message/seat-manage/extraBranch/branchUpdate'
  import extraBranchDel from '@/message/seat-manage/extraBranch/branchDel'
  import extraBranchAdd from '@/message/seat-manage/extraBranch/branchAdd'
  import skillQuery from '@/message/seat-manage/agentSkill/skillQuery'
  import skillUpdate from '@/message/seat-manage/agentSkill/skillUpdate'
  import skillDel from '@/message/seat-manage/agentSkill/skillDel'
  import skillAdd from '@/message/seat-manage/agentSkill/skillAdd'
  import dataQuery from '@/message/wfm/baseData/dictionaryManage/dictionaryQuery'
  import selectTree from "@/components/selectTree5/"
  import branchQuery from '@/message/wfm/baseData/branchManage/branchQuery'

  export default {
    components: {
      selectTree
    },
    data() {
      var dateRules = (rule, value, callback) => {
        if (value.length === 0 || value.length === 1) {
          callback(new Error('请输入日期！'));
        } else {
          callback();
        }
      };
      return {
        branchList: [],//机构
        updateForm: {
          SKILLFLG: '',
          SKILLLEVEL: '',
          SRTDATE: [],
        }, //修改坐席技能表单
        updateRules: {
          SKILLLEVEL: [{
            required: true,
            message: "技能熟练度必输",
            trigger: "blur"
          }],
          SRTDATE: [{
            validator: dateRules,
            trigger: 'change'
          }],
        }, //修改坐席技能验证
        updateIsShow: false, //修改坐席技能的Dialog
        FIELDKEY: [], // 新增坐席技能选中FIELDKEY数组
        multipleSelection: [], // 选中的数据二维数组
        checkList: [], //选中数列
        skillOption: [], // 新增坐席技能
        tableTotal: 1, // 新增坐席技能
        currentPage: 1, // 新增坐席技能
        pageSize: 10, // 新增坐席技能
        addSkillIsShow: false, // 新增坐席技能的dialog
        skillData: [],
        skillIsShow: false,
        extraFlag: '',
        branchForm: { //附属机构
          AGENTDEP: [],
        },
        branchIsShow: false, //附属机构Dialog
        SKILL: false,
        loading: false,
        AGENTTEAMLIST: [],
        skillList: "",
        teamShow: true,
        leveShow: false,
        tableData: [],
        channelTempList: [],
        currentPage: 1,
        currentRow: [],
        RAStruct: [],
        showPWD: true,
        STeamTypeList: [], //班
        teamOption: [], //组
        form: {
          BRANCHNAME: '',
          AGENTCLASS: '', //班
          AGENTID: "",
          AGENTNAME: "",
          AGENTROLE: "",
          AGENTTEAM: "",
          AGENTDEP: "",
          TELPHONE: "",
          EMAIL: "",
          AGENTLEVEL: "",
          LOGINFLG: "",
          LOGINPWD: "",
          AGENTSEX: "",
          ENGLEVEL: "",
          STAFSTS: "",
          SKILLFLG: [],
          SKILLIST: [],
          NUMONLINE: "",
          SKILLEVEL: [],
        },
        AGENTROLELIST: [{
            name: "普通坐席",
            value: "01"
          },
          {
            name: "组长",
            value: "02"
          },
          {
            name: "班长",
            value: "03"
          },
          // {name: "坐席主管",value: "04"},
          // {name: "坐席经理",value: "05"},
          // {name: "质检员",value: "06"},
          // {name: "质检主管",value: "07"},
          // {name: "培训师",value: "08"},
          // {name: "培训主管",value: "09"},
          // {name: "排班师",value: "10"},
          // {name: "排班主管",value: "11"},
          // {name: "知识库普通用户",value: "12"},
          // {name: "知识库管理员",value: "13"}
        ],
        AGENTLEVELLIST: [{
            name: "一星",
            value: "1"
          },
          {
            name: "二星",
            value: "2"
          },
          {
            name: "三星",
            value: "3"
          },
          {
            name: "四星",
            value: "4"
          },
          {
            name: "五星",
            value: "5"
          }
        ],
        LOGINFLGLIST: [{
            name: "指纹",
            value: "0"
          },
          {
            name: "密码",
            value: "1"
          }
        ],
        AGENTSEXLIST: [{
            name: "男",
            value: "1"
          },
          {
            name: "女",
            value: "2"
          }
        ],
        ENGLEVELLIST: [{
            name: "三级",
            value: "3"
          },
          {
            name: "四级",
            value: "4"
          },
          {
            name: "六级",
            value: "6"
          }
        ],
        STAFSTSLIST: [{
            name: "试用",
            value: "01"
          },
          {
            name: "正式上岗",
            value: "02"
          }
        ],
        NUMONLINELIST: [{
            name: "1",
            value: "1"
          },
          {
            name: "2",
            value: "2"
          },
          {
            name: "3",
            value: "3"
          },
          {
            name: "4",
            value: "4"
          },
          {
            name: "5",
            value: "5"
          },
          {
            name: "6",
            value: "6"
          },
          {
            name: "7",
            value: "7"
          },
          {
            name: "8",
            value: "8"
          }
        ],
        SKILLEVELLIST: [{
            name: "1",
            value: "1"
          },
          {
            name: "2",
            value: "2"
          },
          {
            name: "3",
            value: "3"
          },
          {
            name: "4",
            value: "4"
          },
          {
            name: "5",
            value: "5"
          },
          {
            name: "6",
            value: "6"
          },
          {
            name: "7",
            value: "7"
          },
          {
            name: "8",
            value: "8"
          },
          {
            name: "9",
            value: "9"
          },
          {
            name: "10",
            value: "10"
          }
        ],
        SKILLFLGLIST: [{
            name: "电话",
            value: "00"
          },
          {
            name: "视频",
            value: "01"
          },
          {
            name: "文字",
            value: "02"
          }
        ],
        rules: {
          AGENTID: [{
            required: true,
            message: "坐席工号必填",
            trigger: "blur"
          }],
          AGENTNAME: [{
            required: true,
            message: "姓名必填",
            trigger: "blur"
          }],
          AGENTROLE: [{
            required: true,
            message: "班组角色必填",
            trigger: "change"
          }],
          AGENTTEAM: [{
            required: true,
            message: "班组必填",
            trigger: "change"
          }],
          AGENTDEP: [{
            required: true,
            message: "机构必填",
            trigger: "change"
          }],
          AGENTCLASS: [{
            required: true,
            message: "班必填",
            trigger: "change"
          }],
          TELPHONE: [{
            required: true,
            message: "联系方式必填",
            trigger: "blur"
          }],
          EMAIL: [{
            required: true,
            message: "邮箱必填",
            trigger: "blur"
          }],
          AGENTLEVEL: [{
            required: true,
            message: "坐席等级必填",
            trigger: "change"
          }],
          LOGINPWD: [{
            required: true,
            message: "登录密码必填",
            trigger: "blur"
          }],
          STAFSTS: [{
            required: true,
            message: "人员状态必填",
            trigger: "change"
          }],
          SKILLFLG: [{
            required: true,
            message: "受理渠道必填",
            trigger: "change"
          }],
        }
      }
    },
    props: {
      option: Object
    },
    computed: {
      isShow: {
        get: function () {
          return this.option.isShow;
        },
        set: function (newValue) {
          this.option.isShow = newValue;
        }
      }
    },
    watch: {
      'skillOption.FIELDKEY': function (oldVal, newVal) { // 监听数据变化，然后执行分页记忆自动选中回调
        this.$nextTick(() => {
          this.selectMemoriedDataFn();
        })
      },
      // "form.SKILLFLG"(val) {
      //   console.log(val)
      //   if (val.length != 0) {
      //     this.SKILL = true
      //   } else {
      //     this.SKILL = false
      //   }
      // },
      // tableData(n, o) {
      //   this.$nextTick(() => {
      //     for (let i = 0; i < this.RAStruct.length; i++) {
      //       for (let j = 0; j < this.tableData.length; j++) {
      //         console.log(this.tableData[j].SKILLID + ":" + this.RAStruct[i].APPMODULEID);
      //         if (this.tableData[j].SKILLID == this.RAStruct[i].APPMODULEID) {
      //           this.$refs.tableData.toggleRowSelection(this.tableData[j], true);
      //           this.tableData[j].APPMODULELEVEL = this.RAStruct[i].APPMODULELEVEL;
      //         }
      //       }
      //     }
      //     this.RAStruct = [];
      //   })
      // }
    },
    methods: {
       // 查询机构
      async queryBranch() {
        let resBody = new branchQuery()
        resBody.data.BRANCHNO = this.branchNO
        let response = await requestWFM(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.branchList = response.BODY.BRANCHDATA;
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      getBranch(data) {
        this.form.BRANCHNAME = data.BRANCHNAME
        this.form.AGENTDEP = data.BRANCHNO
      },
      closeUpdateDialog() {
        if (this.$refs['updateForm'] != undefined) {
          this.$refs['updateForm'].clearValidate();
          this.$refs['updateForm'].resetFields();
        }
        this.updateForm = {
          SKILLFLG: '',
          SKILLLEVEL: '',
          SRTDATE: [],
        }
      },
      // 修改坐席技能
      saveUpdateSkill(formName) {
        this.$refs[formName].validate(async (valid) => {
          if (valid) {
            let resBody = new skillUpdate();
            resBody.data.AGENTID = this.form.AGENTID
            resBody.data.SKILLFLG = this.updateForm.SKILLFLG
            resBody.data.SKILLLEVEL = this.updateForm.SKILLLEVEL + ''
            resBody.data.SKILLENABLEDATE = this.updateForm.SRTDATE[0]
            resBody.data.ENABLEHOURS = this.updateForm.SRTDATE[1]
            let response = await requestWFM(resBody);
            if (response.SYS_HEAD.ReturnCode == "000000") {
              this.$message({
                message: '修改成功',
                type: 'success'
              });
              this.updateIsShow = false;
              this.querySkill()
            } else {
              this.$message({
                type: "error",
                message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD
                  .ReturnMessage
              })
            }
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      // 修改坐席技能Dialog
      openUpdateSkill(row) {
        this.updateIsShow = true
        this.updateForm = JSON.parse(JSON.stringify(row))
        this.updateForm.SRTDATE = []
        this.updateForm.SRTDATE.push(row.SKILLENABLEDATE)
        this.updateForm.SRTDATE.push(row.ENABLEHOURS)
      },
      // 删除坐席技能
      delSkill(row) {
        this.$confirm('此操作将删除该技能, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {
          let resBody = new skillDel();
          resBody.data.AGENTID = this.form.AGENTID
          resBody.data.SKILLFLG = row.SKILLFLG
          let response = await requestWFM(resBody);
          if (response.SYS_HEAD.ReturnCode == "000000") {
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            this.querySkill()
          } else {
            this.$message({
              type: "error",
              message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
            })
          }
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        });
      },
      // 新增坐席技能
      async saveAddSkill() {
        var dateFlag = false;
        var levelFlag = false
        var transmitData = [];
        if (this.multipleSelection.length > 0) {
          this.multipleSelection.forEach(item => {
            transmitData = [];
            item.forEach((info, i) => {
              if (info.SRTDATE == undefined || info.SRTDATE.length == 0) {
                dateFlag = true;
                return;
              } else if (info.SKILLLEVEL == undefined) {
                levelFlag = true
                return
              } else {
                transmitData.push({
                  'SKILLFLG': info.FIELDKEY,
                  'SKILLLEVEL': info.SKILLLEVEL + '',
                  'SKILLENABLEDATE': info.SRTDATE[0],
                  'ENABLEHOURS': info.SRTDATE[1],
                });
              }
            })
          })
          if (dateFlag) {
            this.$message({
              type: "error",
              message: "请选择日期"
            })
            return;
          }
          if (levelFlag) {
            this.$message({
              type: "error",
              message: "请输入熟练度"
            })
            return;
          }
          let resBody = new skillAdd();
          resBody.data.AGENTID = this.form.AGENTID
          resBody.data.SKILLLIST = transmitData
          let response = await requestWFM(resBody);
          if (response.SYS_HEAD.ReturnCode == "000000") {
            this.$message({
              message: '新增成功',
              type: 'success'
            });
            this.addSkillIsShow = false;
            this.querySkill()
          } else {
            this.$message({
              type: "error",
              message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
            })
          }
          this.addSkillIsShow = false;
        } else {
          this.addSkillIsShow = false;
        }
      },
      // 关闭新增坐席技能时调用
      closeAddSkillDialog() {
        this.skillOption = []
        this.FIELDKEY = []
        this.multipleSelection = []
        this.tableTotal = 0;
        this.currentPage = 1;
        this.checkList = [];
      },
      // 打开新增坐席技能时调用
      openAddSkillDialog() {
        this.checkList = [];
        this.skillDataQuery()
        var list = [];
        if (this.skillData.length > 0) {
          this.skillData.forEach(item => {
            list.push(item.SKILLFLG);
          })
          this.checkList = list ? list : [];
        }
        // this.transmitData = this.rowData = JSON.parse(JSON.stringify(this.option.row)); 

      },
      checkboxInit(row, index) {
        if (this.checkList.indexOf(row.FIELDKEY) != -1) {
          return false; //不可勾选
        } else {
          return true; //可勾选
        }
      },
      changeFun(val) {
        this.$nextTick(() => {
          let FIELDKEY = []
          this.multipleSelection.forEach(L => L.forEach(M => FIELDKEY.push(M.FIELDKEY)))
          this.FIELDKEY = FIELDKEY;
        })
      },
      selectAll(selection) { // 全选切换方法
        if (selection.length) { // 全选
          this.multipleSelection[this.currentPage - 1] = selection
        } else { // 全不选
          this.multipleSelection[this.currentPage - 1] = []
        }
      },
      selectMemoryFn(val, row) { // 设置分页记忆二位数组方法
        // 注意：val 传过来默认为数组类型 ，row 为 Object（当前选择数据对象）
        let currentArr = this.multipleSelection[this.currentPage - 1] // 当前分页对应数组
        if (!currentArr) {
          this.multipleSelection[this.currentPage - 1] = val // 不存在这个二维数组，则创建这个二位数组
        } else { // 存在
          if (val.includes(row)) { // 选中
            this.multipleSelection[this.currentPage - 1] = val
          } else { // 取消
            for (var i = 0; i < currentArr.length; i++) {
              if (currentArr[i]) {
                if (currentArr[i].FIELDKEY == row.FIELDKEY) {
                  delete currentArr[i];
                  break;
                }
              }
            }
          }
        }
      },
      selectMemoriedDataFn() { // 分页记忆自动选中方法
        let currentArr = this.multipleSelection[this.currentPage - 1] // 当前分页对应被选中数据
        if (currentArr && currentArr.length) { // 存在则继续执行
          let tempRowsIDs = this.skillOption.map(L => L.FIELDKEY) // 当前分页被选中数据的id集合
          currentArr.forEach((item, index) => { // 遍历当前分页被选中数据
            if (tempRowsIDs.includes(item.FIELDKEY)) { // id匹配上，则选中
              this.$refs.multipleTable.toggleRowSelection(this.skillOption[tempRowsIDs.indexOf(item.FIELDKEY)])
            }
          })
        }
      },
      // 坐席技能分页
      handleCurrentChange(val) {
        this.currentPage = val;
        this.skillDataQuery()
      },
      //前端分页
      handleSizeChange(val) {
        this.pageSize = val;
        this.skillDataQuery()
      },
      // 查询坐席技能数据字典
      async skillDataQuery() {
        let resBody = new dataQuery();
        resBody.data.FIELDCODE = 'AGENTSKILL'
        resBody.data.CurrPage = this.currentPage;
        resBody.data.PageRowNum = this.pageSize;
        let response = await requestWFM(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.skillOption = response.BODY.FIEDATA;
          // if(this.skillOption.length>0){
          //   this.skillOption.forEach(item=>{
          //     item.SKILLLEVEL = 0.1
          //   })
          // }
          this.tableTotal = response.BODY.TotalRowNum;
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      // 新增坐席技能Dialog
      addSkillDialog() {
        this.addSkillIsShow = true
      },
      // 打开配置坐席的Dialog
      openSkill() {
        this.skillIsShow = true
      },
      // 打开配置坐席技能Dialog时调用
      async openSkillConfig() {
        this.querySkill()
        // let resBody = new skillQuery();
        // resBody.data.AGENTID = this.form.AGENTID;
        // let response = await requestWFM(resBody);
        // if (response.SYS_HEAD.ReturnCode == "000000") {
        //   this.skillData = response.BODY.SKILLLIST
        // } else {
        //   this.$message({
        //     type: "error",
        //     message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
        //   })
        // }
      },
      async querySkill() {
        let resBody = new skillQuery();
        resBody.data.AGENTID = this.form.AGENTID;
        let response = await requestWFM(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.skillData = response.BODY.SKILLLIST
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      // 关闭配置坐席技能Dialog时调用
      closeSkillConfig() {

      },
      // 关闭坐席附属机构的Dialog
      closeExtraBranch() {
        this.branchForm.AGENTDEP = []
      },
      // 打开坐席附属机构的dialog
      async openExtraBranch() {
        this.queryBranch()
        let resBody = new extraBranchQuery();
        resBody.data.AGENTID = this.form.AGENTID;
        let response = await requestWFM(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.extraFlag = response.BODY.AUXDATA.length == 0 ? 'add' : 'update'
          if (this.extraFlag == 'update') {
            let arr = response.BODY.AUXDATA[0]
            for (let key in arr) {
              if(key != 'AUX_BRNAME1' &&key != 'AUX_BRNAME2' && key != 'AUX_BRNAME3'&& arr[key] != '') {
                this.branchForm.AGENTDEP.push(arr[key])
              }
            }
          }
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      // 删除坐席附属机构
      async delExtra() {
        let resBody = new extraBranchDel();
        resBody.data.AGENTID = this.form.AGENTID;
        let response = await requestWFM(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.$message({
            message: '删除成功',
            type: 'success'
          });
          this.branchIsShow = false
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      // 修改坐席附属机构
      async updateExtra() {
        let resBody = new extraBranchUpdate();
        resBody.data.AGENTID = this.form.AGENTID;
        resBody.data.AUX_BRNO1 = this.branchForm.AGENTDEP[0] != undefined ? this.branchForm.AGENTDEP[0] : ''
        resBody.data.AUX_BRNO2 = this.branchForm.AGENTDEP[1] != undefined ? this.branchForm.AGENTDEP[1] : ''
        resBody.data.AUX_BRNO3 = this.branchForm.AGENTDEP[2] != undefined ? this.branchForm.AGENTDEP[2] : ''
        let response = await requestWFM(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.$message({
            message: '修改成功',
            type: 'success'
          });
          this.branchIsShow = false
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      // 新增坐席附属机构
      async addExtra() {
        let resBody = new extraBranchAdd();
        resBody.data.AGENTID = this.form.AGENTID;
        resBody.data.AUX_BRNO1 = this.branchForm.AGENTDEP[0] != undefined ? this.branchForm.AGENTDEP[0] : ''
        resBody.data.AUX_BRNO2 = this.branchForm.AGENTDEP[1] != undefined ? this.branchForm.AGENTDEP[1] : ''
        resBody.data.AUX_BRNO3 = this.branchForm.AGENTDEP[2] != undefined ? this.branchForm.AGENTDEP[2] : ''
        let response = await requestWFM(resBody);
        if (response.SYS_HEAD.ReturnCode == "000000") {
          this.$message({
            message: '新增成功',
            type: 'success'
          });
          this.branchIsShow = false
          this.branchForm.AGENTDEP = []
        } else {
          this.$message({
            type: "error",
            message: "请求失败，错误码:" + response.SYS_HEAD.ReturnCode + "，错误信息：" + response.SYS_HEAD.ReturnMessage
          })
        }
      },
      // 保存配置坐席附属机构
      saveExtraBranch() {
        if (this.extraFlag == 'add') {
          this.addExtra()
        } else {
          this.updateExtra()
        }
      },
      // 当选择坐席附属机构时，附属机构不能包含主机构
      changeBranch() {
        let i = this.branchForm.AGENTDEP.indexOf(this.form.AGENTDEP)
        if (i != -1) {
          this.$message.error('所选附属机构不能和主机构一致！');
          this.branchForm.AGENTDEP.splice(i, 1)
        }
      },
      // 配置附属机构Dialog
      openBranch() {
        this.branchIsShow = true
      },
      // 查询班
      squery() {
        this.loading = true;
        let resBody = new teamManage();
        resBody.data.OPERATION = "4";
        resBody.data.TEAMTYPE = "1";
        requestYg(resBody)
          .then(response => {
            if (response.SYS_HEAD.ReturnCode === "000000") {
              this.STeamTypeList = response.RSP_BODY.struct;
              for (let i = 0; i < this.STeamTypeList.length; i++) {
                const element = this.STeamTypeList[i];
                this.STeamTypeMap[element.TEAMID] = element.TEAMNAME;
              }
              this.agentQuery();
            } else {
              this.$message({
                type: "error",
                message: "请求失败，错误码: " + response.SYS_HEAD.ReturnCode + ",错误信息: " + response.SYS_HEAD.ReturnMessage
              });
              this.STeamTypeList = [];
            }
          })
          .catch(error => {
            this.loading = false;
          })
      },
      // 查询组
      async teamQuery() {
        //debugger
        let resBody = new teamManage();
        resBody.data.OPERATION = '4'
        resBody.data.TEAMTYPE = '2'
        resBody.data.PAGEFLAG = 4
        resBody.data.CURRPAGE = 1
        resBody.data.PAGEROWNUM = 100
        resBody.data.HTEAMID = this.form.AGENTCLASS
        let response = await requestYg(resBody);
        if (response.SYS_HEAD.ReturnCode === "000000") {
          this.teamOption = response.RSP_BODY.struct
        } else {
          this.$message({
            type: "error",
            message: '该班下没有对应组'
          });
          this.teamOption = []
          this.form.GENTTEAM = ''
        }
      },
      // 切换班
      changeClass() {
        this.form.AGENTTEAM = ''
        this.teamQuery()
      },
      // checkInput(val){
      //   if((val<'1'||val>'10')&&val!=''){
      //     this.$aui.message.show({
      //           type: "error",
      //           message: "技能等级请输入1-10之间的整数"
      //         });
      //   }
      // },
      add() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            // this.loading = true;
            let resBody = "";
            resBody = new agentManage();
            if (this.option.log == "1") {
              resBody.data.OPERATION = '1'
            } else if (this.option.log == "2") {
              resBody.data.OPERATION = '2'
            }
            resBody.data.AGENTID = this.form.AGENTID;
            resBody.data.AGENTNAME = this.form.AGENTNAME;
            resBody.data.AGENTSEX = this.form.AGENTSEX;
            resBody.data.AGENTTEAM = this.form.AGENTTEAM;
            resBody.data.AGENTDEP = this.form.AGENTDEP;
            resBody.data.AGENTCLASS = this.form.AGENTCLASS;
            resBody.data.AGENTROLE = this.form.AGENTROLE;
            resBody.data.TELPHONE = this.form.TELPHONE;
            resBody.data.EMAIL = this.form.EMAIL;
            resBody.data.STAFSTS = this.form.STAFSTS;
            resBody.data.AGENTLEVEL = this.form.AGENTLEVEL;
            resBody.data.LOGINFLG = this.form.LOGINFLG;
            resBody.data.LOGINPWD = this.form.LOGINPWD;
            // resBody.data.ENGLEVEL = this.form.ENGLEVEL;
            // resBody.data.NUMONLINE = this.form.NUMONLINE == "" ? "1" : this.form.NUMONLINE;
            resBody.data.MULTITYPE = this.form.SKILLFLG.join('|');
            console.log(resBody.data)
            // console.log(this.form.SKILLFLG);
            // resBody.data.SKILLEVEL = "9";
            // let MODULEIDLIST = [];
            // let CHANNELLIST = [];
            // this.channelTempList = this.form.SKILLFLG;
            // let tempname = "";
            // let tempList = {};
            // for (let i = 0; i < this.channelTempList.length; i++) {
            // tempname=  this.channelTempList[i];
            // tempList[tempname] = '9';
            // CHANNELLIST.push({
            //   'SKILLFLG': this.channelTempList[i],
            //   'SKILLLEVEL': '9',
            //   'AGENTID': this.form.AGENTID,
            //   'AGENTNAME': this.form.AGENTNAME
            // });
            //CHANNELLIST.push({tempname:'9'});

            // }
            // for (let i = 0; i < this.currentRow.length; i++) {

            //   // m.set('APPMODULEID',this.currentRow[i].SKILLID);
            //   // m.set('APPMODULELEVEL',this.currentRow[i].APPMODULELEVEL)
            //   MODULEIDLIST.push({
            //     'APPMODULEID': this.currentRow[i].SKILLID,
            //     'APPMODULELEVEL': this.currentRow[i].APPMODULELEVEL,
            //     'AGENTID': this.form.AGENTID,
            //     'AGENTNAME': this.form.AGENTNAME
            //   });
            // }
            // resBody.data.CHANNELLIST = CHANNELLIST;
            // resBody.data.MODULEIDLIST = MODULEIDLIST;

            requestYg(resBody)
              .then(response => {
                if (response.SYS_HEAD.ReturnCode === "000000") {
                  let mes = this.option.log == "1" ? "创建" : "修改";
                  this.$message({
                    type: "success",
                    message: `坐席信息管理${mes}${response.SYS_HEAD.ReturnMessage}!`
                  });
                  this.isShow = false;
                  this.$emit("refreshTable");
                } else {
                  this.$message({
                    type: "error",
                    message: `${response.SYS_HEAD.ReturnMessage}!`
                  });
                }
                this.loading = false;
              })
              .catch(error => {
                this.loading = false;
              });
          } else {
            this.$message({
              type: "warning",
              message: "请输入合法的数据！"
            });
            return false;
          }
        });
      },
      updateDate() {
        this.form.AGENTID = this.option.currentRow.AGENTID;
        this.form.AGENTNAME = this.option.currentRow.AGENTNAME;
        this.form.AGENTROLE = this.option.currentRow.AGENTROLE;
        this.form.AGENTTEAM = this.option.currentRow.AGENTTEAM;
        this.form.AGENTDEP = this.option.currentRow.AGENTDEP;
        this.form.AGENTCLASS = this.option.currentRow.AGENTCLASS;
        this.form.BRANCHNAME = this.option.currentRow.BRANCHNAME;
        this.form.TELPHONE = this.option.currentRow.TELPHONE;
        this.form.EMAIL = this.option.currentRow.EMAIL;
        this.form.AGENTLEVEL = this.option.currentRow.AGENTLEVEL;
        this.form.LOGINFLG = this.option.currentRow.LOGINFLG;
        this.form.LOGINPWD = this.option.currentRow.LOGINPWD;
        this.form.AGENTSEX = this.option.currentRow.AGENTSEX;
        // this.form.ENGLEVEL = this.option.currentRow.ENGLEVEL;
        this.form.STAFSTS = this.option.currentRow.STAFSTS;
        this.form.SKILLFLG = this.option.currentRow.MULTITYPE.split('|');
        // this.form.NUMONLINE = this.option.currentRow.NUMONLINE;
      },
      // levelClick() {
      //   this.leveShow = true;
      // },
      // 技能查询
      skillQuery() {
        //   let resBody = new skillQuery();
        //   resBody.data.OPERATION = "S";
        //   for (let i = 0; i < this.form.SKILLFLG.length; i++) {
        //     this.skillList = this.skillList + "," + this.form.SKILLFLG[i];
        //   }
        //   console.log(this.skillList);
        //   resBody.data.channelId = this.skillList;
        //   requestYg(resBody)
        //     .then(response => {
        //       if (response.SYS_HEAD.ReturnCode === "000000") {
        //         this.skillList = response.RSP_BODY.RspStruct || [];
        //         this.tableData = response.RSP_BODY.RspStruct || [];
        //       }
        //       // else {
        //       //   this.$aui.message.show({
        //       //       type: "error",
        //       //       message: response.RSP_BODY.ReturnMessage
        //       //     });
        //       // }
        //     })
      },
      // detailQuery() {
      //   let resBody = new agentManage();
      //   resBody.data.AGENTID = this.option.currentRow.AGENTID;
      //   requestYg(resBody)
      //     .then(response => {
      //       console.log("-----------" + response.RSP_BODY.struct);
      //       if (response.SYS_HEAD.ReturnCode === "000000") {
      //         // this.form.STAFSTS =  response.RSP_BODY.AGENTSTAFSTS;
      //         let RCStruct = response.RSP_BODY.RspChlStruct;
      //         this.RAStruct = response.RSP_BODY.RspAppStruct;
      //         this.form.SKILLFLG = [];
      //         for (let i = 0; i < RCStruct.length; i++) {
      //           this.form.SKILLFLG.push(RCStruct[i].SKILLFLG);
      //         }
      //         // this.skillQuery()

      //       } else {
      //         this.$aui.message.show({
      //           type: "error",
      //           message: response.RSP_BODY.ReturnMessage
      //         });
      //       }
      //     })
      // },
      openCreate() {
        if (this.$refs['form'] != undefined) {
          this.$refs['form'].clearValidate();
          this.$refs['form'].resetFields();
        }
        this.squery() //查询班
        if (this.option.log == '2') {
          this.updateDate();
          // this.detailQuery();
          // this.form.SKILLFLG="";
        } else if (this.option.log == '1') {
          // this.$refs.form.clearValidate();
          this.form.AGENTID = "";
          this.form.AGENTNAME = "";
          this.form.AGENTROLE = "";
          this.form.AGENTTEAM = "";
          this.form.AGENTDEP = "";
          this.form.AGENTCLASS = "";
          this.form.TELPHONE = "";
          this.form.EMAIL = "";
          this.form.AGENTLEVEL = "";
          this.form.LOGINFLG = "";
          this.form.LOGINPWD = "";
          this.form.AGENTSEX = "";
          this.form.ENGLEVEL = "";
          this.form.STAFSTS = "";
          this.form.NUMONLINE = "";
          this.form.SKILLFLG = [];
          this.tableData = [];
        } else {
          this.updateDate();
          // this.detailQuery()
          // this.form.SKILLFLG = "";
        }

      },
      closedialog() {
        this.$refs.form.clearValidate(); //清楚表单验证
        this.$refs.form.resetFields();
        this.$emit("refreshTable");
      },
    }
  }

</script>
